package cyc2018.贪心思想;

/**
 * 买卖股票的最佳时机 II
 */
public class Test122 {

    // 遍历数组，低价买、高价卖，并累加收益即可
    public static int maxProfit(int[] prices) {
        int profit = 0;
        for (int i = 0; i < prices.length; i++) {
            if (i + 1 < prices.length && prices[i] < prices[i+1]) {
                profit += (prices[i+1] - prices[i]);
            }
        }
        return profit;
    }

    public static void main(String[] args) {
        int[] a = {7,1,5,3,6,4};
//        int[] a = {1,2,3,4,5};
        System.out.println(maxProfit(a));
    }
}
